package com.ling.travels.service;

import com.ling.travels.dao.ProvinceDao;
import com.ling.travels.pojo.Province;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 编程之外
 * @company lingStudy
 * @create 2020-06-29 18:16
 */
@Service
@Transactional
public class ProvinceServiceImpl implements ProvinceService {

    @Autowired
    private ProvinceDao provinceDao;

    //分页查询所有省份信息 page:当前页，rows:每页显示的记录数
    @Override
    public List<Province> findByPage(String name, Integer page, Integer rows) {
        //起始页码 = (当前页码 -1)*每页条数
        int start = (page - 1) * rows;
        return provinceDao.findByPage("%" + name + "%", start, rows);
    }

    //查询数据总条数  总页数=总条数/每页显示的记录数
    @Override
    public Integer findTotals(String name) {
        return provinceDao.findTotals("%" + name + "%");
    }

    //保存省份方法
    @Override
    public void save(Province province) {
        provinceDao.save(province);
    }

    @Override
    public void delete(String id) {
        provinceDao.delete(id);
    }
}
